<template>
  <div
    class="ellipsis"
    :class="{ 'ellipsis-line': row === 1, 'ellipsis-lines': row > 1 }"
    :title="hoverTip ? content : null"
    :style="{ '--row': row }"
  >
    <slot name="pre"></slot>
    <span class="content">{{ content }}</span>
    <slot name="aft"></slot>
  </div>
</template>

<script setup>
defineProps({
  row: {
    type: Number,
    default: 1
  },
  hoverTip: {
    type: Boolean,
    default: false
  },
  content: {
    type: String,
    default: ""
  }
});
</script>

<style lang="scss" scoped>
.ellipsis-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ellipsis-lines {
  display: -webkit-box;
  word-break: break-all;
  overflow: hidden;
  text-overflow: ellipsis;
  -webkit-line-clamp: var(--row);
  -webkit-box-orient: vertical;
}
</style>
